import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from 'vue';
import {Tag} from 'ant-design-vue';
import {getTaskTypeList} from "/@/api/taskCenter/taskType";

const taskTypeList = await getTaskTypeList();
export const columns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 50,
    align: 'center',
  },
  {
    title: '姓名',
    dataIndex: 'fname',
    width: 100,
    align: 'center',
  },
  {
    title: '工号',
    dataIndex: 'fnumber',
    width: 150,
    align: 'center',
  },
  {
    title: '职称',
    dataIndex: 'type',
    width: 140,
    align: 'center',
  },
  {
    title: '部门',
    dataIndex: 'class',
    width: 180,
    align: 'center',
  },
  {
    title: '教学课时',
    dataIndex: 'jxks',
    width: 160,
    align: 'center',
  },
  {
    title: '教学课时-差值',
    dataIndex: 'jxkscl',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const max = record.jxks_full_mark;
      const abs = record.jxks - max == 0 ? '' : record.jxks - max > 0 ? '+' : '-'
      return `${abs}${Math.abs(record.jxks - max)}`
    },
  },
  {
    title: '教科研积分',
    dataIndex: 'jkyjf',
    width: 100,
    align: 'center',
  },
  {
    title: '教科研积分-差值',
    dataIndex: 'jkyjfcl',
    width: 150,
    align: 'center',
    customRender: ({record}) => {
      const max = record.jkyjf_full_mark;
      const abs = record.jkyjf - max == 0 ? '' : record.jkyjf - max > 0 ? '+' : '-'
      return `${abs}${Math.abs(record.jkyjf - max)}`
    },
  },
  {
    title: '教科研建设积分',
    dataIndex: 'jkyjsjf',
    width: 160,
    align: 'center',
  },
  {
    title: '教科研建设积分-差值',
    dataIndex: 'jkyjsjfcl',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const max =  record.jkyjsjf_full_mark;
      const abs = record.jkyjsjf - max == 0 ? '' : record.jkyjsjf - max > 0 ? '+' : '-'
      return `${abs}${Math.abs(record.jkyjsjf - max)}`
    },
  },
  {
    title: '管理与公共服务积分',
    dataIndex: 'glyggfwjf',
    width: 180,
    align: 'center',
  },
  {
    title: '管理与公共服务积分-差值',
    dataIndex: 'glyggfwjfcl',
    width: 200,
    align: 'center',
    customRender: ({record}) => {
      const max = record.glyggfwjf_full_mark;
      const abs = record.glyggfwjf - max == 0 ? '' : record.glyggfwjf - max > 0 ? '+' : '-'
      return `${abs}${Math.abs(record.glyggfwjf - max)}`
    },
  },
  // {
  //   title: '备注',
  //   dataIndex: 'tips',
  //   width: 160,
  //   align: 'center',
  // },
  {
    title: '完成状态',
    dataIndex: 'complete',
    width: 160,
    align: 'center',
    customRender: ({record}) => {
      const status_name = ['未完成', '部分完成', '超量完成'];
      const color_name = ['red', 'blue', 'green'];
      return h(Tag, {color: color_name[record.complete - 1]}, () => status_name[record.complete - 1]);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'task_type',
    label: '任务类型',
    component: 'ApiSelect',
    componentProps: {
      api: getTaskTypeList,
      params: {},
      labelField: 'name',
      valueField: 'id',
    },
    colProps: {span: 8},
  },
  {
    field: 'complete',
    label: '完成情况',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '未完成',
          value: 1,
        },
        {
          label: '部分完成',
          value: 2,
        },
        {
          label: '超量完成',
          value: 3,
        },
      ]
    },
    colProps: {span: 8},
  },
];
